package de.fhhof.robot.control;

import java.util.HashMap;
import java.util.Map;

import de.fhhof.robot.control.net.Connection;
import de.fhhof.robot.control.net.IConnection;

public class ConnectionFactory {

	private static Map<String, IConnection> connections = new HashMap<String, IConnection>();
	
	public static IConnection getConnection(int serverPort,String senderId,String receiverId){
		
		String key = serverPort+"-"+ senderId+"-"+receiverId;
		IConnection connection = null;
		if(connections.containsKey(key)){
			connection = connections.get(key);
		}
		else{
			connection = new Connection(serverPort, senderId, receiverId);
			connections.put(key, connection);
		}
		return  connection;
	}
	public static IConnection getConnection(String host,int port,String senderId,String receiverId){
		
		String key = host+ "-"+port+"-"+ senderId+"-"+receiverId;
		IConnection connection = null;
		if(connections.containsKey(key)){
			connection = connections.get(key);
		}
		else{
			connection = new Connection(host, port, senderId, receiverId);
			connections.put(key, connection);
		}
		return  connection;
	}
	public static IConnection getOpenedConnection(String key){
		return connections.get(key);
	}
	
}
